package database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DatabaseConn {
	private static final String JDBC_URL = "jdbc:mysql://localhost:3306/citypro?characterEncoding=UTF-8";
	private static final String JDBC_USER = "root";
	private static final String JDBC_PWD = "123456";
	private static Connection conn = null;
	/**	创建数据库连接的方法
	 * @return返回一个Connection类型的数据库连接
	 */
	public Connection getConnection(){
		try {
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PWD);	//创建连接
		} catch (Exception e) {
			e.printStackTrace();
		}
		return conn;
	}//end getConnection
	/**关闭数据库连接
	 * @param conn	取得连接
	 */
	public void close(){
		try {
			this.conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
